package com.example.annotation.contextholders;

import lombok.extern.slf4j.Slf4j;

/**
 * @author fz
 * @creation time 2021/5/20
 */
@Slf4j
public class DynamicDataSourceContextHolder {
    //用来隔离线程
    private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>();

    public static void setDataSourceType(String dsType) {
        log.info("切换到{}数据源", dsType);
        CONTEXT_HOLDER.set(dsType);
    }

    public static String getDataSourceType() {
        return CONTEXT_HOLDER.get();
    }

    public static void removeDataSourceType() {
        CONTEXT_HOLDER.remove();
    }
}
